﻿--[[
    @brief    ui logic for user_guide ui
    @author   hqzheng
    @version  1.0
    @date     2017-07-08
--]]

user_guide_model =
{
    user_guide_config = nil;
    cfg_name = "user_guide_config.js";
    user_guide_item = "15";
    user_guide_local_config_key = "user_guide.my_user_guide_config";
    has_get_show_flag = false;
    need_show_user_guide = false;
    has_show_mainframe = false;
    has_notify_show = false;
    cur_page_index = 1;  -- 初始化处于第一帧

    is_showing_user_guide = false;
    
    default_param = {
        url = LoadStr("USER_GUIDE_URL"),
        report_type = "login_user_guide",
        need_focus_home = true,
        guide_show_callback = function()
            return;
        end,
        guide_close_callback = function()
            return;
        end,
        on_js_callback = function(uilib, func_name, json_str)
            return;
        end,
    };
    show_param = nil;
    
    init = function()
        -- body
    end;

    init_config = function(param)
        user_guide_model.show_param = user_guide_model.default_param;
        if param == nil then
            return;
        end
        for key, value in pairs(param) do
            user_guide_model.show_param[key] = value;
        end;
    end;

    save_user_guide_config = function (version)
        local data = {};
        data["common"] = 0;
        data["key"] = user_guide_model.user_guide_local_config_key;
        local config_tb = {};
        config_tb["version"] = version;
        config_tb["is_show"] = "1";
        data["value"] = base_utility.table_to_json(config_tb);
        comm_center.call_service("Svr_SetConfig", data);
    end;

    get_user_guide_config = function ()
        local data = {};
        data["common"] = 0;
        data["key"] = user_guide_model.user_guide_local_config_key;
        local config = comm_center.call_service("Svr_GetConfig", data);
        return config;
    end;

    user_guide_report = function (item_type, sub_item_type, page_index)
        local report_data = ierd_tgp.tpf_ui.LuaQosDataEx:new();
        local pv_data = {};
        if nil ~= item_type then
            pv_data["type"] = item_type;
        end

        if nil ~= sub_item_type then
            pv_data["sub_type"] = sub_item_type;
        end

        if nil ~= page_index then
            pv_data["index"] = page_index;            
        end

        if nil ~= report_data then
            report_data.oc_type = 1;
            report_data.qos_kind = ierd_tgp.adapt_for_imports.qos.Qos_kind.kGameUpdateLackSpace;
            report_data.str_action = "user_guide"
            report_data.str_type = "user_guide_report";
            report_data.str_json = base_utility.table_to_json(pv_data);
            base_utility.lua_qos_ex(report_data);
            report_data:delete();
        end
    end;
};

user_guide_model.init();